//
//  AppDelegate.m
//  StudyRN
//
//  Created by 朱吉峥 on 2020/2/13.
//  Copyright © 2020 朱吉峥. All rights reserved.
//

#import "AppDelegate.h"
#import "PYTabBarController.h"
#import "PYRNUpdate.h"
#import "NSData+PYUploader.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    /// RNupdate
    [PYRNUpdate checkRNUpdate];
    self.window = [[UIWindow alloc] init];
    [self.window makeKeyAndVisible];
    self.window.rootViewController = [[PYNavigationController alloc] initWithRootViewController:[PYTabBarController new]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self uploadAssets];
    return YES;
}

- (void)uploadJsBundle
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    if (data) {
        [data uploadToQiniu:^(float percent) {
            NSLog(@"percent = %f", percent);
        } completion:^(NSString * _Nonnull urlString) {
            NSLog(@"urlString = %@", urlString);
        }];
    }
}

- (void)uploadAssets
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"assets" withExtension:nil];
    NSData *data = [NSData dataWithContentsOfURL:url];
    if (data) {
        [data uploadToQiniu:^(float percent) {
            NSLog(@"percent = %f", percent);
        } completion:^(NSString * _Nonnull urlString) {
            NSLog(@"urlString = %@", urlString);
        }];
    }
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [PYRNUpdate checkRNUpdate];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [PYRNUpdate checkRNUpdate];
}

#pragma mark - 横竖屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return [PYScreenRotateManager supportedInterfaceOrientations];
}
@end
